<?php
$ret['result']='failed';
if ($_FILES["file"]["error"] > 0){
	$ret['error']=$_FILES['file']['error'];
	header('Content-type:text/json');
	echo json_encode($ret,JSON_UNESCAPED_UNICODE);
	return;
}

if ((($_FILES["file"]["type"] != "image/gif")
		&& ($_FILES["file"]["type"] != "image/jpeg")
		&& ($_FILES["file"]["type"] != "image/pjpeg")
		&& ($_FILES['file']['type'] != "image/png" )
	|| ($_FILES["file"]["size"] > 20000) ){
	$ret['error'] = 'type or size is illegal';
	header('Content-type:text/json');
	echo json_encode($ret,JSON_UNESCAPED_UNICODE);
	return;
}
  
if (file_exists("pics/" . $_FILES["file"]["name"])){
	$ret['error'] = 'duplicated file';
}else{
	move_uploaded_file($_FILES["file"]["tmp_name"],	"pics/" . $_FILES["file"]["name"]);
	$ret['result']='success';
}
header('Content-type:text/json');
echo json_encode($ret,JSON_UNESCAPED_UNICODE);
?>   
